<?php
namespace app\common\model;
use \think\facade\Log; 
use think\Model;
use think\Facade\Db;

class Regions extends Model
{
	protected $name = 'regions';
	protected $pk = 'region_id';
    /**
     * 获取列表
     * @return array 列表
     */
    public function getProvince($where=['region_grade'=>1], $orderby=''){	
    	$result = array();
    	empty($orderby) && $orderby = $this->pk.' asc';
		try{
			empty($orderby) && $orderby = $this->pk.' desc';
			$result = Db::name($this->name)->where($where)->order($orderby)->select();
		}catch(\Exception $e){
			throw new \Exception($e->getMessage());
		}
		
		return $result;
    }
    public function getCity($region_id, $orderby=''){	
    	$result = array();
    	empty($orderby) && $orderby = $this->pk.' asc';
    	$where['p_region_id'] = $region_id;
		try{
			empty($orderby) && $orderby = $this->pk.' desc';
			$result = Db::name($this->name)->where($where)->order($orderby)->select();
		}catch(\Exception $e){
			throw new \Exception($e->getMessage());
		}
		
		return $result;
    }
    public function getArea($region_id, $orderby=''){	
    	$result = array();
    	empty($orderby) && $orderby = $this->pk.' asc';
    	$where['p_region_id'] = $region_id;
		try{
			empty($orderby) && $orderby = $this->pk.' desc';
			$result = Db::name($this->name)->where($where)->order($orderby)->select();
		}catch(\Exception $e){
			throw new \Exception($e->getMessage());
		}
		
		return $result;
    }
}
